package com.kotlin.heimaplayer.net

import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import java.lang.reflect.ParameterizedType

/**
 * 所有请求的基类
 */

open class MRequest<RESPONSE>(val type:Int,val url:String,val handler: ResponseHandler<RESPONSE>) {
    fun parseResult(result:String?):RESPONSE{
        println(result)
        val gson = Gson()
        val type = (this.javaClass.genericSuperclass as ParameterizedType).actualTypeArguments[0]
        val res = gson.fromJson<RESPONSE>(result,type)

        return res
    }

    /**
     * 发送网络请求
     */
    fun excute(){
        NetManager.manager.sendRequest(this)
    }

}